package com.yan.crowd.constant;

import java.util.HashSet;
import java.util.Set;

/**
 * 可以被放行的资源
 */
public class AccessPassResources {

    public static final Set<String> PASS_RES_SET = new HashSet<>();

    static {
        PASS_RES_SET.add("/");
        PASS_RES_SET.add("/auth/member/to/reg/page");
        PASS_RES_SET.add("/auth/member/to/login/page");
        PASS_RES_SET.add("/auth/member/logout");
        PASS_RES_SET.add("/auth/member/do/logout");
        PASS_RES_SET.add("auth/member/send/short/message");
        PASS_RES_SET.add("/auth/member/do/register");
    }

    public static final Set<String> STATIC_RES_SET = new HashSet<>();

    static {
        STATIC_RES_SET.add("bootstrap");
        STATIC_RES_SET.add("css");
        STATIC_RES_SET.add("fonts");
        STATIC_RES_SET.add("img");
        STATIC_RES_SET.add("jquery");
        STATIC_RES_SET.add("script");
        STATIC_RES_SET.add("ztree");
    }

    public static boolean judgeCurrentServletPathStaticResource(String servletPath) {

        if (servletPath == null || servletPath.length() == 0) {
            throw new RuntimeException(CrowdConstant.MESSAGE_SYSTEM_ERROR_NOT_UNIQUE);
        }

        String[] split = servletPath.split("/");
        String level1 = split[1];

        return STATIC_RES_SET.contains(level1);
    }

}
